#define _CRT_SECURE_NO_WARNINGS 1

//猜数字游戏

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void menu();//函数声明

void game();//函数声明

int main()
{
	int i = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("Please choose a number:");
		scanf("%d", &i);
		switch (i)
		{
		case 1:
			game();
			break;
		case 0:
			printf("quit the game\n");
		default:
			printf("error,please choose again");
		}

	} while (i);
	return 0;
}
void menu()
{
	printf("**********\n");
	printf("**1.play**\n");
	printf("**0.quit**\n");
	printf("**********\n");
}

void game()
{
	int number = 0;
	int ret = rand() % 100 + 1;//生成随机数
	int count = 5;//控制机会
	while (count)
	{
		printf("\n你还有%d次机会\n", count);
		printf("Please input a number\n");
		scanf("%d", &number);
		if (number > ret)
		{
			printf("猜大了");
		}
		else if (number < ret)
		{
			printf("猜小了");
		}
		else
		{
			printf("恭喜你，猜对了");
			break;
		}
		count--;
	}
	if (!count)
	{
		printf("你失败了，正确答案是：%d\n", ret);
	}
}

